home *** CD-ROM | disk | FTP | other *** search
/ Mac OS on the PowerPC Mic…rocessor - In Store Demo / Mac OS on the PowerPC Microprocessor.iso / MacOS / MacOS.dxr / 00087_bookmark_script.ls < prev    next >
Encoding:
Text File  |  1996-05-13  |  7.4 KB  |  230 lines

  1. property iBookMarkSprite, iBookMarkCastList, iBookMarkList, iCurrentBookMarkStatus, iCurrentChapter, iCurrentParagraph, iVisitedMarkList, iMaxChapter, iMaxParagraphList, objMisc, iPreferenceFileName, iPreferenceFolder, iAllMarkList, iPreferenceExist, iUserName, iSavePreference
  2. global objfileio, galllessonlist, gBookmarkLoc, gGraphicPath, gDelimiter, onIBM, gBookmarkLoginText, gLogin
  3.  
  4. on birth me
  5.   set iBookMarkCastList to []
  6.   mImportPict(me, "BMOFFUP.PCT")
  7.   mImportPict(me, "BMOFFDN.PCT")
  8.   mImportPict(me, "BMONUP.PCT")
  9.   mImportPict(me, "BMONDN.PCT")
  10.   set iBookMarkSprite to 23
  11.   set the puppet of sprite iBookMarkSprite to 1
  12.   set the castNum of sprite iBookMarkSprite to getAt(iBookMarkCastList, 1)
  13.   set the loc of sprite iBookMarkSprite to gBookmarkLoc
  14.   set iBookMarkList to []
  15.   set iCurrentBookMarkStatus to 0
  16.   set iCurrentChapter to 0
  17.   set iCurrentParagraph to 0
  18.   set iVisitedMarkList to []
  19.   set iMaxChapter to count(galllessonlist)
  20.   set iMaxParagraphList to []
  21.   repeat with tChapter = 1 to iMaxChapter
  22.     add(iMaxParagraphList, getAt(getAt(galllessonlist, tChapter), 2))
  23.   end repeat
  24.   set objMisc to birth(script "Misc_script")
  25.   set iPreferenceFileName to EMPTY
  26.   mGetPreferenceFile(me)
  27.   return me
  28. end
  29.  
  30. on mImportPict me, tPictName
  31.   set tCast to the number of cast tPictName
  32.   importFileInto(cast tCast, gGraphicPath & tPictName)
  33.   set the regPoint of cast tCast to point(getAt(the rect of cast tCast, 1), getAt(the rect of cast tCast, 2))
  34.   add(iBookMarkCastList, tCast)
  35. end
  36.  
  37. on mGetMaxChapter me
  38.   return iMaxChapter
  39. end
  40.  
  41. on mGetMaxParagraph me, tChapter
  42.   return getAt(iMaxParagraphList, tChapter)
  43. end
  44.  
  45. on mGetStatus me, tChapter, tParagraph
  46.   set tVisited to getAt(getAt(iVisitedMarkList, tChapter), tParagraph)
  47.   set tMarked to getAt(getAt(iBookMarkList, tChapter), tParagraph)
  48.   if tVisited then
  49.     if tMarked then
  50.       return #VISITED_MARKED
  51.     else
  52.       return #VISITED
  53.     end if
  54.   else
  55.     if tMarked then
  56.       return #MARKED
  57.     else
  58.       return #NORMAL
  59.     end if
  60.   end if
  61. end
  62.  
  63. on mGetPreferenceFile me
  64.   global gJPWinFont
  65.   if onIBM then
  66.     set iPreferenceFolder to mGetPreferenceFolder(objMisc) & "CDfBMark"
  67.   else
  68.     set iPreferenceFolder to mGetPreferenceFolder(objMisc) & "CDF BookMarks"
  69.   end if
  70.   set tTempItemDelimiter to the itemDelimiter
  71.   set the itemDelimiter to "."
  72.   if onIBM then
  73.     set tFileName to item 1 of the movie & ".Pfs"
  74.   else
  75.     set tFileName to item 1 of the movie & " Prefs"
  76.   end if
  77.   set the itemDelimiter to tTempItemDelimiter
  78.   set iPreferenceFileName to iPreferenceFolder & gDelimiter & tFileName
  79.   if mFileExists(objMisc, iPreferenceFileName) then
  80.     set iAllMarkList to value(line 2 of fileIOread(iPreferenceFileName))
  81.     set iPreferenceExist to 1
  82.   else
  83.     set iAllMarkList to [:]
  84.     set iPreferenceExist to 0
  85.   end if
  86.   if the romanLingo then
  87.     if onIBM then
  88.       set tFont to "MS Sans Serif"
  89.     else
  90.       set tFont to "Geneva"
  91.     end if
  92.   else
  93.     if onIBM then
  94.       set tFont to gJPWinFont
  95.     else
  96.       set tFont to "Osaka"
  97.     end if
  98.   end if
  99.   set the text of cast "LoginQuestion" to line 1 of gBookmarkLoginText
  100.   set the textFont of cast "LoginQuestion" to tFont
  101.   set the text of cast "LoginUserName" to line 2 of gBookmarkLoginText
  102.   set the textFont of cast "LoginUserName" to tFont
  103.   set the text of cast "LoginOkButton" to line 3 of gBookmarkLoginText
  104.   set the textFont of cast "LoginOkButton" to tFont
  105.   set the text of cast "LoginCancelButton" to line 4 of gBookmarkLoginText
  106.   set the textFont of cast "LoginCancelButton" to tFont
  107.   set gLogin to 1
  108. end
  109.  
  110. on mLogIn me, theUserName
  111.   set iUserName to theUserName
  112.   if iUserName = "Cancel" then
  113.     mNewUser(me)
  114.     set iSavePreference to 0
  115.   else
  116.     if iUserName = EMPTY then
  117.       mNewUser(me)
  118.       set iSavePreference to 0
  119.     else
  120.       if findPos(iAllMarkList, iUserName) then
  121.         set tUserPreference to getaProp(iAllMarkList, iUserName)
  122.         set iBookMarkList to the BOOKMARK of tUserPreference
  123.         set iVisitedMarkList to the VISITED of tUserPreference
  124.         set iSavePreference to 1
  125.       else
  126.         mNewUser(me)
  127.         set iSavePreference to 1
  128.       end if
  129.     end if
  130.   end if
  131. end
  132.  
  133. on mNewUser me
  134.   set iBookMarkList to []
  135.   set iVisitedMarkList to []
  136.   repeat with tChapter = 1 to iMaxChapter
  137.     set tMaxParagraph to getAt(iMaxParagraphList, tChapter)
  138.     set tBookmarkList to []
  139.     set tVisitedmarkList to []
  140.     if tMaxParagraph <> 0 then
  141.       setAt(tBookmarkList, tMaxParagraph, 0)
  142.       setAt(tVisitedmarkList, tMaxParagraph, 0)
  143.     end if
  144.     add(iBookMarkList, tBookmarkList)
  145.     add(iVisitedMarkList, tVisitedmarkList)
  146.   end repeat
  147. end
  148.  
  149. on mSaveBookMarkPreference me
  150.   if iSavePreference then
  151.     if not mFolderExists(objMisc, iPreferenceFolder) then
  152.       mInsureFolder(objMisc, iPreferenceFolder & gDelimiter)
  153.     end if
  154.     set tPreferenceList to [:]
  155.     addProp(tPreferenceList, #BOOKMARK, iBookMarkList)
  156.     addProp(tPreferenceList, #VISITED, iVisitedMarkList)
  157.     addProp(tPreferenceList, #date, the date)
  158.     addProp(tPreferenceList, #time, the time)
  159.     setaProp(iAllMarkList, iUserName, tPreferenceList)
  160.     set tPreferenceText to EMPTY
  161.     put "Copyright CDF Technologies" into line 1 of tPreferenceText
  162.     put string(iAllMarkList) into line 2 of tPreferenceText
  163.     fileIOwrite(iPreferenceFileName, tPreferenceText)
  164.   end if
  165.   mClose(objMisc)
  166. end
  167.  
  168. on mVisible me, tWhich
  169.   set the visible of sprite iBookMarkSprite to tWhich
  170. end
  171.  
  172. on mMouseDown me
  173.   repeat while stillDown()
  174.     if rollOver(iBookMarkSprite) then
  175.       if iCurrentBookMarkStatus then
  176.         set the castNum of sprite iBookMarkSprite to getAt(iBookMarkCastList, 4)
  177.       else
  178.         set the castNum of sprite iBookMarkSprite to getAt(iBookMarkCastList, 2)
  179.       end if
  180.     else
  181.       if iCurrentBookMarkStatus then
  182.         set the castNum of sprite iBookMarkSprite to getAt(iBookMarkCastList, 3)
  183.       else
  184.         set the castNum of sprite iBookMarkSprite to getAt(iBookMarkCastList, 1)
  185.       end if
  186.     end if
  187.     updateStage()
  188.   end repeat
  189.   if rollOver(iBookMarkSprite) then
  190.     if iCurrentBookMarkStatus then
  191.       set iCurrentBookMarkStatus to 0
  192.       setAt(getAt(iBookMarkList, iCurrentChapter), iCurrentParagraph, 0)
  193.       set the castNum of sprite iBookMarkSprite to getAt(iBookMarkCastList, 1)
  194.     else
  195.       set iCurrentBookMarkStatus to 1
  196.       setAt(getAt(iBookMarkList, iCurrentChapter), iCurrentParagraph, 1)
  197.       set the castNum of sprite iBookMarkSprite to getAt(iBookMarkCastList, 3)
  198.     end if
  199.   else
  200.     if iCurrentBookMarkStatus then
  201.       set the castNum of sprite iBookMarkSprite to getAt(iBookMarkCastList, 3)
  202.     else
  203.       set the castNum of sprite iBookMarkSprite to getAt(iBookMarkCastList, 1)
  204.     end if
  205.   end if
  206.   updateStage()
  207. end
  208.  
  209. on mSetBookmarkButton me, tChapter, tParagraph
  210.   set iCurrentChapter to tChapter
  211.   set iCurrentParagraph to tParagraph
  212.   set iCurrentBookMarkStatus to getAt(getAt(iBookMarkList, iCurrentChapter), iCurrentParagraph)
  213.   if iCurrentBookMarkStatus then
  214.     set the castNum of sprite iBookMarkSprite to getAt(iBookMarkCastList, 3)
  215.   else
  216.     set the castNum of sprite iBookMarkSprite to getAt(iBookMarkCastList, 1)
  217.   end if
  218. end
  219.  
  220. on mSetVisited me, tChapter, tParagraph
  221.   setAt(getAt(iVisitedMarkList, tChapter), tParagraph, 1)
  222. end
  223.  
  224. on mSetBookMark me, tChapter, tParagraph
  225.   set tNewBookmarkStatus to not getAt(getAt(iBookMarkList, tChapter), tParagraph)
  226.   set tVisitedmarkStatus to getAt(getAt(iVisitedMarkList, tChapter), tParagraph)
  227.   setAt(getAt(iBookMarkList, tChapter), tParagraph, tNewBookmarkStatus)
  228.   return list(tNewBookmarkStatus, tVisitedmarkStatus)
  229. end
  230.